﻿using System.ComponentModel;
using Vroom.Common.Config;
using Vroom.Common.Enums;

namespace Vroom.Config
{
    public class ConfigItem : IConfigItem, INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        //if (_IsEnabled != value)  { _IsEnabled = value; IsDirty = true; }

        public string _DestinationConnectionAlias;
        public string DestinationConnectionAlias { get { return _DestinationConnectionAlias; } set { if (_DestinationConnectionAlias != value) { _DestinationConnectionAlias = value; IsDirty = true; }; OnPropertyChanged("DestinationConnectionAlias"); } }

        public string _DestinationConnectionString;
        public string DestinationConnectionString { get { return _DestinationConnectionString; } set { if (_DestinationConnectionString != value) { _DestinationConnectionString = value; IsDirty = true; } OnPropertyChanged("DestinationConnectionString"); } }

        public string _Destination;
        public string Destination { get { return _Destination; } set { if (_Destination != value) { _Destination = value; IsDirty = true; } OnPropertyChanged("Destination"); } }

        public string _Source;
        public string Source { get { return _Source; } set { if (_Source != value) { _Source = value; IsDirty = true; } OnPropertyChanged("Source"); } }

        public string _SourceShortName;
        public string SourceShortName { get { return _SourceShortName; } set { if (_SourceShortName != value) { _SourceShortName = value; IsDirty = true; }; OnPropertyChanged("SourceShortName"); } }

        public string _MappingsOverrides;
        public string MappingsOverrides { get { return _MappingsOverrides; } set { if (_MappingsOverrides != value) { _MappingsOverrides = value; IsDirty = true; } OnPropertyChanged("MappingsOverrides"); } }

        public int? _SourceHeaderRowCount;
        public int? SourceHeaderRowCount { get { return _SourceHeaderRowCount; } set { if (_SourceHeaderRowCount != value) { _SourceHeaderRowCount = value; IsDirty = true; } OnPropertyChanged("SourceHeaderRowCount"); } }

        public string _ExplicitNullColumns;
        public string ExplicitNullColumns { get { return _ExplicitNullColumns; } set { if (_ExplicitNullColumns != value) { _ExplicitNullColumns = value; IsDirty = true; } OnPropertyChanged("ExplicitNullColumns"); } }

        public int _IsEnabled;
        public int IsEnabled { get { return _IsEnabled; } set { if (_IsEnabled != value)  { _IsEnabled = value; IsDirty = true; } OnPropertyChanged("IsEnabled"); } }

        public bool _IsDirty;
        public bool IsDirty { get { return _IsDirty; } set { _IsDirty = value; OnPropertyChanged("IsDirty"); } }

        public SourceSystem _SourceSystem;
        public SourceSystem SourceSystem { get { return _SourceSystem; } set { if (_SourceSystem != value) { _SourceSystem = value; IsDirty = true; } OnPropertyChanged("SourceSystem"); } }

        public SourceType _SourceType;
        public SourceType SourceType { get { return _SourceType; } set { if (_SourceType != value) { _SourceType = value; IsDirty = true; } OnPropertyChanged("SourceType"); } }

        public DestinationType _DestinationType;
        public DestinationType DestinationType { get { return _DestinationType; } set { if (_DestinationType != value) { _DestinationType = value; IsDirty = true; } OnPropertyChanged("DestinationType"); } }

        public ColumnMappingType _ColumnMappingType;
        public ColumnMappingType ColumnMappingType { get { return _ColumnMappingType; } set { if (_ColumnMappingType != value) { _ColumnMappingType = value; IsDirty = true; } OnPropertyChanged("ColumnMappingType"); } }

        public ConfigItem()
        {
            SetMappings();
            IsDirty = false;
        }


        public void SetMappings()
        {
            if (string.IsNullOrEmpty(MappingsOverrides))
            {
                MappingsOverrides = string.Empty;
            }
        }

        #region INotifyPropertyChanged Method

        protected void OnPropertyChanged(string name)
        {
            PropertyChangedEventHandler handler = PropertyChanged;

            if (handler != null)
                handler(this, new PropertyChangedEventArgs(name));
        }

        #endregion

    }
}
